import React from 'react';
import { Form } from 'antd';
import { connect } from 'dva';
import moment from 'moment';
import Formorder from './Formorder';

export default connect(({ order }: any) => ({
  view: order.view,
  personData: order.personData,
  commodityData: order.commodityData,
  hourseData: order.hourseData,
  utilsData: order.utilsData,
  ishourse: true,
}))(
  Form.create({
    onFieldsChange(props: any, changedFields) {
      const value: any = Object.values(changedFields)[0];
      props.dispatch({
        type: 'order/updateView',
        payload: {
          [value.name]: value.value,
        },
      });
    },
    mapPropsToFields(props: any) {
      console.log(props,'propsddd')
      return {
        type: Form.createFormField({
          value: String(props.view.type),
        }),
        quantityUnitId: Form.createFormField({
          value: props.view.quantityUnitId,
        }),
        staffId: Form.createFormField({
          value: props.view.staffId,
        }),
        wineId: Form.createFormField({
          value: props.view.wineId,
        }),
        companyPrice: Form.createFormField({
          value: props.view.companyPrice,
        }),
        companySalePrice: Form.createFormField({
          value: props.view.companySalePrice,
        }),
        staffPrice: Form.createFormField({
          value: props.view.staffPrice,
        }),
        quantity: Form.createFormField({
          value: props.view.quantity,
        }),
        freight: Form.createFormField({
          value: props.view.freight,
        }),
        otherFee: Form.createFormField({
          value: props.view.otherFee,
        }),
        otherFeeComments: Form.createFormField({
          value: props.view.otherFeeComments,
        }),
        companyProfitProportion: Form.createFormField({
          value: String(props.view.companyProfitProportion),
        }),
        description: Form.createFormField({
          value: props.view.description,
        }),
        dealTime: Form.createFormField({
          value: moment(props.view.dealTime),
        }),
        comments: Form.createFormField({
          value: props.view.comments,
        }),
        wareHouseCode: Form.createFormField({
          value: props.view.wareHouseCode,
        }),
      };
    },
  })(Formorder),
);
